<template>
  <div>
    <h2>库存统计</h2>
    <div class="chart" id="myEcharts">
      图表的容器
    </div>
  </div>
</template>

<script>
import { inject, onMounted, reactive } from 'vue'

export default {
  setup () {
    const $echarts = inject('echarts')
    const $http = inject('axios')

    const data = reactive({})

    async function getState () {
      data.value = await $http({
        url: '/three/data'
      })
    }

    onMounted(() => {
      getState().then(() => {
        const myChart = $echarts.init(document.getElementById('myEcharts'))
        myChart.setOption({
          legend: {
            top: 'bottom'
          },
          tooltip: {
            show: true
          },
          series: [
            {
              type: 'pie',
              data: data.value.data.chartData.chartData,
              radius: [10, 100],
              center: ['50%', '45%'],
              roseType: 'area',
              itemStyle: {
                borderRadius: 10
              }
            }
          ]
        })
      })
    })
    return {
      getState,
      data
    }
  }
}
</script>

<style scoped>
.chart{
  height: 4.5rem;
}
h2{
  height: .6rem;
  color: #fff;
  line-height: .6rem;
  font-size: .25rem;
  text-align: center;
}
</style>
